#coding:utf-8
import numpy as np
import cPickle
from math import floor
from scipy.interpolate import interp2d
import matplotlib.pyplot as plt

X,Y,H = cPickle.load(open('hanggai.pkl'))

nbinx = floor((np.max(X) - np.min(Y)) / 50.0)
nbiny = floor((np.max(Y) - np.min(Y)) / 50.0)
His,_,_ = np.histogram2d(X, Y, bins=[nbinx, nbiny])
nOcc = len(np.where(His > 1)[0])
print('occupied ratio %f' % (nOcc / (nbinx*nbiny)))

# interplate
X = X - np.min(np.min(X))
Y = Y - np.min(np.min(Y))
f = interp2d(x=X, y=Y, z=H, kind='linear')
Xnew = np.arange(0, 50, np.max(X))
Ynew = np.arange(0, 50, np.max(Y))
Hnew = f(Xnew, Ynew)
plt.matshow(Hnew)
plt.show()

